Muhammad Mudassir Khan (mudasssir.khan@ucp.edu.pk)
from IPython.display import Image
Image(filename='./images/challenges.jpeg', width=500)
from IPython.display import YouTubeVideo
YouTubeVideo("TeFF9wXiFfs")
YouTubeVideo("M5pj2CrO-2w")
Mitchell ( 1997 ) define Machine Learning as “A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P , if its performance at tasks in T , as measured by P , improves with experience E .”
Example: playing checkers.
T = the task of playing checkers.
E = the experience of playing many games of checkers
P = the probability that the program will win the next game.
Image(filename='./images/01_01.png', width=500)
Image(filename='./images/01_02.png', width=500)
Image(filename='./images/01_04.png', width=300)
Image(filename='./images/01_11.png', width=500)
Image(filename='./images/01_03.png', width=300)
Image(filename='./images/01_12.png', width=600)
Image(filename='./images/01_06.png', width=300)
Image(filename='./images/01_05.png', width=300)
Image(filename='./images/01_08.png', width=450)
Image(filename='./images/01_09.png', width=500)
from __future__ import print_function
import numpy as np
import tflearn
# Download the Titanic dataset
from tflearn.datasets import titanic
titanic.download_dataset('titanic_dataset.csv')
# Load CSV file, indicate that the first column represents labels
from tflearn.data_utils import load_csv
data, labels = load_csv('titanic_dataset.csv', target_column=0,
categorical_labels=True, n_classes=2)
# Preprocessing function
def preprocess(data, columns_to_ignore):
# Sort by descending id and delete columns
for id in sorted(columns_to_ignore, reverse=True):
[r.pop(id) for r in data]
for i in range(len(data)):
# Converting 'sex' field to float (id is 1 after removing labels column)
data[i][1] = 1. if data[i][1] == 'female' else 0.
return np.array(data, dtype=np.float32)
# Ignore 'name' and 'ticket' columns (id 1 & 6 of data array)
to_ignore=[1, 6]
# Preprocess data
data = preprocess(data, to_ignore)
print (data)
[[ 1. 1. 29. 0. 0.
211.3374939 ]
[ 1. 0. 0.91670001 1. 2.
151.55000305]
[ 1. 1. 2. 1. 2.
151.55000305]
...,
[ 3. 0. 26.5 0. 0.
7.2249999 ]
[ 3. 0. 27. 0. 0.
7.2249999 ]
[ 3. 0. 29. 0. 0. 7.875 ]]
# Build neural network
net = tflearn.input_data(shape=[None, 6])
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 32)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net)
# Define model
model = tflearn.DNN(net)
# Start training (apply gradient descent algorithm)
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True)
Training Step: 819 | total loss: 0.50917 | time: 0.347s | Adam | epoch: 010 | loss: 0.50917 - acc: 0.7704 -- iter: 1296/1309 Training Step: 820 | total loss: 0.49590 | time: 0.349s | Adam | epoch: 010 | loss: 0.49590 - acc: 0.7746 -- iter: 1309/1309 --
# Let's create some data for DiCaprio and Winslet
dicaprio = [3, 'Jack Dawson', 'male', 19, 0, 0, 'N/A', 5.0000]
winslet = [1, 'Rose DeWitt Bukater', 'female', 17, 1, 2, 'N/A', 100.0000]
user = [2, 'user', 'female', 20, 0, 2, 'N/A', 50.0000]
# Preprocess data
dicaprio, winslet, user = preprocess([dicaprio, winslet, user], to_ignore)
# Predict surviving chances (class 1 results)
pred = model.predict([dicaprio, winslet, user])
print("DiCaprio Surviving Rate:", pred[0][1])
print("Winslet Surviving Rate:", pred[1][1])
print("user Surviving Rate:", pred[2][1])
DiCaprio Surviving Rate: 0.09548981487751007 Winslet Surviving Rate: 0.8807896375656128 user Surviving Rate: 0.7699385285377502
from IPython.display import YouTubeVideo
YouTubeVideo("V1eYniJ0Rnk")
from datetime import timedelta
start=int(timedelta(hours=0, minutes=7, seconds=47).total_seconds())
YouTubeVideo("BfDQNrVphLQ", start=start, autoplay=1, theme="light", color="red")
Image(filename='./images/01_10.png', width=500)
YouTubeVideo("PQCrX1sQSzY")
YouTubeVideo("MqUbdd7ae54")
Music Generation
Art Generation (Mario levels)
Story Writing
Speech recognition (personal assistants, chat bots)
Face recognition
Lung cancer detection --- prize $1,000,000
Youtube 8m video tagging --- prize $100,000
Detect and classify fish --- prize $150,000
IMAGENET (Large Scale Visual Recognition) --- Fame
Efficient ConvNets for Semantic Segmentation --- prize undeclared
Titanic survival prediction --- Fame and ranking
Machine learning is at the heart of all technologies today.
start=int(timedelta(hours=0, minutes=1, seconds=23).total_seconds())
YouTubeVideo("jBLN1UJbiyw", start=start, autoplay=1, theme="light", color="red")
Raschka, Sebastian. Python machine learning. Birmingham, UK: Packt Publishing, 2015. Print.